package app.server.project.main.service.dto.recharge;

import app.server.project.core.constants.Def;
import app.server.project.core.util.MathUtil;
import app.server.project.main.service.constants.LuckType;
import app.server.project.main.service.service.recharge.CallbackType;
import app.server.project.main.service.service.recharge.PayStatus;
import app.server.project.main.service.service.recharge.RechargeType;
import app.server.project.main.service.service.upay.UPayType;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.time.LocalDateTime;

@Data
public class RechargeOrderDto {


    private String id;


    private String userId;


    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private String createTime;


    private int payType;

    private int status;

    private long amount;

    private String amountStr;
    private int typeId;
    private long consumeNum;
    private String consumeStr;
    private String param;
    private String statusStr;
    private int callbackType;
    private String callbackTypeStr;
    private String walletAddress;
    private String remark;
    private String nick;
    private int rechargeCfgId;
    private String starTitle;
    private String payTypeStr;

    private String adChannel;

    private String country;

    private String failDes;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime regTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime lastOfflineTime;


    private String choice;
    private String hash;
    private String highVal;
    private long tonVal;
    private String tonValStr;
    private String rewardType;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime successTime;

    public void setStatus(int status) {
        this.status = status;
        if (status == PayStatus.Wait) {
            this.statusStr = "待支付";
        } else if (status == PayStatus.Finish) {
            this.statusStr = "支付成功";
        } else if (status == PayStatus.Close) {
            this.statusStr = "服务器主动关闭ton超时订单";
        } else if (status == PayStatus.Human) {
            this.statusStr = "人工补单";
        } else if (status == PayStatus.ClientClose) {
            this.statusStr = "客户端主动关闭ton订单";
        }
    }

    public void setCallbackType(int callbackType) {
        this.callbackType = callbackType;
        if (callbackType == CallbackType.Energy) {
            this.callbackTypeStr = "体力充值";
        } else if (callbackType == CallbackType.Race) {
            this.callbackTypeStr = "解锁赛道";
        } else if (callbackType == CallbackType.Sign) {
            this.callbackTypeStr = "补签";
        } else if (callbackType == CallbackType.Click) {
            this.callbackTypeStr = "点击次数";
        } else if (callbackType == CallbackType.Rate) {
            this.callbackTypeStr = "爆率";
        } else if (callbackType == CallbackType.BtcLuck) {
            this.callbackTypeStr = "比特币抽奖";
        } else if (callbackType == CallbackType.SOLLuck) {
            this.callbackTypeStr = "SOL抽奖";
        } else if (callbackType == CallbackType.USDTRate) {
            this.callbackTypeStr = "USDT抽奖";
        }
    }


    public void flushStr() {
        if (this.payType == RechargeType.TON) {
            this.payTypeStr = "ton支付";
            this.consumeStr = MathUtil.getNumFormat(this.consumeNum, Def.Ton);
            this.amountStr = MathUtil.getNumFormat(this.amount, Def.Ton);
        } else if (this.payType == RechargeType.Star) {
            this.payTypeStr = "星星支付";
            this.consumeStr = MathUtil.getNumFormat(this.consumeNum, 1);
            this.amountStr = MathUtil.getNumFormat(this.amount, 1);
        } else if (this.payType == RechargeType.USDT) {
            this.payTypeStr = "USDT支付";
            this.consumeStr = MathUtil.getNumFormat(this.consumeNum, UPayType.U_Rate);
            this.amountStr = MathUtil.getNumFormat(this.amount, UPayType.U_Rate);
        }
        if (this.tonVal > Def.Zero) {
            if (this.payType == RechargeType.USDT) {
                this.tonValStr = MathUtil.getNumFormat(this.tonVal, UPayType.U_Rate);
            } else {
                this.tonValStr = MathUtil.getNumFormat(this.tonVal, LuckType.TonRate);
            }

        }
    }
}
